home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / compass.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  2KB  |  117 lines

  1. /* --------------------------------- compass.c ------------------------------ */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* display a compass on the edge of this window.
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. extern void FAR
  14. show_compass (HUD *h, OBJECT *p, int mode)
  15. {
  16.     int    i, j, tx, ty, x0, y0, x1, y1, x2, y2, dd, dd2, mx, my;
  17.     int    sqr, ortho;
  18.     int    D[2];
  19.     VECT    RR;
  20.     ANGLE    a;
  21.  
  22.     if (!(HDD_COMPASS & EX->hdd))
  23.         return;
  24.  
  25.     if (HDT_MAP == mode)
  26.         a = 0;
  27.     else if (HDT_RADAR == mode)
  28.         a = -p->a[Z];
  29.     else
  30.         return;
  31.  
  32.     RR[Y] = -FONE;
  33.     tx = num_size (9L, h->ss)+1;
  34.     ty = h->ss/2+1;
  35.  
  36.     my = h->ss;
  37.     mx = muldiv (my, h->sx, h->sy);
  38.  
  39.     sqr = HDD_SQRCOMPASS & EX->hdd;
  40.     ortho = sqr && (HDD_ORTCOMPASS & EX->hdd);
  41.     a = -a;
  42.     for (i = 0; i < 36; i += 1, a += DEG(10)) {
  43.         RR[X] = SIN(a);
  44.         RR[Z] = COS(a);
  45.         if (sqr)
  46.             clip_to_screen (D, RR, h->maxx, h->maxy, h->maxx,
  47.                 h->maxy, 0);
  48.         else {
  49.             D[X] = fmul (RR[X], h->maxx);
  50.             D[Y] = fmul (RR[Z], h->maxy);
  51.         }
  52.         x0 = h->orgx+D[X];
  53.         y0 = h->orgy-D[Y];
  54.         j = i%3;
  55.         if (i >= 10 ) {
  56.             dd2 = tx;
  57.             dd  = tx*2;
  58.         } else {
  59.             dd2 = tx/2;
  60.             dd  = tx;
  61.         }
  62.         if (ortho) {
  63.             if (D[X] == h->maxx) {        /* right */
  64.                 x1 = mx;
  65.                 x2 = dd;
  66.                 y1 = 0;
  67.                 y2 = ty;
  68.             } else if (D[X] == -h->maxx) {    /* left */
  69.                 x1 = -mx;
  70.                 x2 = -2;
  71.                 y1 = 0;
  72.                 y2 = ty;
  73.             } else if (D[Y] == h->maxy) {    /* top */
  74.                 x1 = 0;
  75.                 x2 = dd2;
  76.                 y1 = my;
  77.                 y2 = h->ss+2;
  78.             } else if (D[Y] == -h->maxy) {    /* bottom */
  79.                 x1 = 0;
  80.                 x2 = dd2;
  81.                 y1 = -my;
  82.                 y2 = -2;
  83.             } else            /* should never reach here */
  84.                 continue;
  85.         } else {
  86.             x1 = muldiv (D[X], mx, h->maxx);
  87.             y1 = muldiv (D[Y], my, h->maxy);
  88.             x2 = fmul (RR[X], dd2) + dd2;
  89.             y2 = fmul (RR[Z],  ty) +  ty;
  90.         }
  91.         if (j) {
  92.             x1 /= 2;
  93.             y1 /= 2;
  94.         }
  95.         gr_color (CC_GREEN);
  96.         gr_move (x0,    y0);
  97.         gr_draw (x0-x1, y0+y1);
  98.         if (!j) {
  99.             x0 -= x1+x2;
  100.             y0 += y1+y2;
  101.             if (ortho) {
  102.                 x1 = h->maxx-mx;
  103.                 y1 = h->maxy-my;
  104.                 if (y0 >= h->orgy+y1)
  105.                     y0 = h->orgy+y1;
  106.                 else if (y0-h->ss < h->orgy-y1)
  107.                     y0 = h->orgy-y1+h->ss;
  108.                 else if (x0+dd > h->orgx+x1)
  109.                     x0 = h->orgx+x1-dd;
  110.                 else if (x0 <= h->orgx-x1)
  111.                     x0 = h->orgx-x1+1;
  112.             }
  113.             stroke_num (x0, y0, i, h->ss, CC_GREEN);
  114.         }
  115.     }
  116. }
  117.